package com.jwgf.faultnavigation;

import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

import androidx.fragment.app.DialogFragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.jwgf.adapter.MultiItemTypeAdapter;
import com.jwgf.common.AppContext;
import com.jwgf.smarowindingmachine_unity.R;

import java.util.ArrayList;
import java.util.List;

public class FaultNavigationDetailDialog extends DialogFragment {

    public static String KEY = "fault_code";
    private RecyclerView recyclerView;
    private MultiItemTypeAdapter<Object> adapter;

    private List<Object> list = new ArrayList<>();

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        LayoutInflater inflater = getActivity().getLayoutInflater();
        View v = inflater.inflate(R.layout.recycler_view, null);
        int code = getArguments().getInt(KEY);
        FaultNavigationAttr attr = FaultNavigationMap.getInstance().get(code);
        recyclerView = (RecyclerView) v.findViewById(R.id.recycler);
        list.addAll(attr.steps);
        adapter = new MultiItemTypeAdapter<>(AppContext.getInstance(), list);
        adapter.addItemViewDelegate(new FaultNavigationDetailDelegate());
        GridLayoutManager layoutManager = new GridLayoutManager(getActivity(), 1);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle(getResources().getString(attr.name) + "(点击图片可以放大)");
        builder.setView(v);
        return builder.create();
    }

    @Override
    public void onResume() {
        super.onResume();
        getDialog().getWindow().setLayout(600, 460);
    }

}
